package com.example.pay_service.controller;

import com.example.pay_service.return_data.Mall_Data;
import com.example.pay_service.service.ShopcartService;
import com.example.pay_service.vo.Address;
import com.example.pay_service.vo.Commodity;
import com.example.pay_service.vo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @title: ShopcartController
 * @projectName mall
 * @description: TODO
 * @author TLJ
 * @date 2021/12/1411:22
 */

@RestController
@RequestMapping("/pay")
public class ShopcartController {

    @Autowired
    ShopcartService shopcartService;

    @RequestMapping("/showcommodity")
    public Mall_Data show(@RequestParam("id") int id){
        Commodity commodities = shopcartService.show(id);
        if (commodities!=null){
            Mall_Data mall_data = new Mall_Data();
            mall_data.setcode(1);
            mall_data.seterror("查询成功");
            mall_data.setdata(commodities);
            return mall_data;
        }

        Mall_Data mall_data = new Mall_Data();
        mall_data.setcode(0);
        mall_data.seterror("查询失败");
        mall_data.setdata("");
        return mall_data;
    }

    @RequestMapping("showaddress")
    public Mall_Data showaddress(@RequestParam("user_id") String user_id){
        System.out.println(11111);
        List<Address> addresses = shopcartService.showaddress(user_id);
        if (addresses.size()>0){
            Mall_Data mall_data = new Mall_Data();
            mall_data.setcode(1);
            mall_data.seterror("查询地址成功");
            mall_data.setdata(addresses);
            return mall_data;
        }
        Mall_Data mall_data = new Mall_Data();
        mall_data.setcode(0);
        mall_data.seterror("查询地址失败");
        mall_data.setdata("");
        return mall_data;
    }


}
